package com.xzy.g;

import com.xzy.service.StudentService;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * 说明：
 *
 * @author xzy
 * @date 2021/12/5 17:28
 */
@Slf4j
@ToString
public class ServiceA implements InitializingBean {
    private StudentService studentService;

    public ServiceA() {
        log.info("实例化 => {}", "ServiceA()");
    }

    @Autowired
    public void setStudentService(StudentService studentService) {
        log.info("属性赋值|依赖注入 => setStudentService(StudentService studentService)");
        this.studentService = studentService;
    }

    @PostConstruct
    public void postConstruct() {
        log.info("初始化前 => @PostConstruct");
    }

    @MyPostConstruct
    public void myPostConstruct() {
        log.info("初始化前 => @MyPostConstruct");
    }

    /**
     * Invoked by the containing {@code BeanFactory} after it has set all bean properties
     * and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.
     * <p>This method allows the bean instance to perform validation of its overall
     * configuration and final initialization when all bean properties have been set.
     *
     * @throws Exception in the event of misconfiguration (such as failure to set an
     *                   essential property) or if initialization fails for any other reason
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("初始化 => {}", this);
    }
}